package models

import (
	"OnlineRetailers/controllers/errorDeal"
	errorDeal2 "OnlineRetailers/models/errorDeal"
	"github.com/garyburd/redigo/redis"
)

var Pool *redis.Pool

func init() {
	Pool = &redis.Pool{
		MaxIdle:     16,
		MaxActive:   0,
		IdleTimeout: 300,

		Dial: func() (redis.Conn, error) {
			log := &errorDeal2.Log{}
			//return redis.Dial("tcp", "192.168.2.101:6379")
			c, err := redis.Dial("tcp", "42.194.131.65:6380")
			//c, err := redis.Dial("tcp", "127.0.0.1:6379")

			if err != nil {
				errorDeal.ErrMess(log, "400", err, "redis", err.Error())
				return nil, err
			}
			if _, err := c.Do("AUTH", "public123456"); err != nil {
				c.Close()
				return nil, err
			}
			if _, err := c.Do("SELECT", 2); err != nil {
				c.Close()
				errorDeal.ErrMess(log, "400", err, "redis", err.Error())
				return nil, err
			}
			return c, nil
		},
	}
}
